from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect


class AuthMiddleware(MiddlewareMixin):

    def process_request(self, request):
        #防止无限重定向，如果当前请求的URL是这个，则通过
         if request.path_info=='/login/':
             return None
         #验证cookie是否存在
         cookie=request.session.get("info")
         if cookie:
             print('存在cookie')
             return
         else:
             return redirect('/login/')
